package model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="Warehouses")

public class Warehouse {
	@Id
	private String name;
	
	@OneToMany(mappedBy="warehouse", cascade=CascadeType.ALL)
	private List<Department> departments = new ArrayList<Department>();
	
	
	public Warehouse(){
		
	}
	public Warehouse(String name){
		this.name = name;
	}
	
	public List<Department> getAllDepartment(){
		return new ArrayList<Department>(departments);
	}
	
	Department createDepartmentUD(Warehouse warehouse, String name, String description){
		Department department = new Department(warehouse, name, description);
		departments.add(department);
		return department;
	}
	
	void removeDepartmentUD(Department department){
		departments.remove(department);
	}
	
	public Department createDepartment(Warehouse warehouse, String name, String description){
		Department department = this.createDepartmentUD(warehouse, name, description);
		department.setWarehouseUD(this);
		return department;
	}
	
	public void removeDepartment(Department department){
		department.setWarehouseUD(null);
		this.removeDepartmentUD(department);
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	

	
}
